/**
 * Created by Administrator on 2017/4/5.
 */
import ng from 'angular';
import rt from 'angular-ui-router';
import angularJsXlsx from 'angular-js-xlsx';
import './common/index.scss';
import animate from 'angular-animate';

import  wife from './commponents/wife/index.js';
import husband from  './commponents/husband/inxdex.js';
//指令
import dir from './directy/selectDir/index';
import autoHeight from './directy/angularInit/autoHeight';
import slide from './directy/angularInit/slideDown';
import tip from './directy/tip/index';
//factroy
import arcFun from './directy/d3fun/arcChange';
import chartFun from './directy/d3fun/chart';
import treeFun from './directy/d3fun/tree';
//创建angualrApp
var app = ng.module('app', [
  rt,
  animate,
  angularJsXlsx.name,
  autoHeight.name,
  slide.name,
  tip.name,
  wife.name,
  husband.name,
  arcFun.name,
  chartFun.name,
  treeFun.name,
  dir.name,

]).config(['$urlRouterProvider', function ($urlRouterProvider) {
  // $urlRouterProvider.otherwise('/');
}]);
//进行请求的封装
var sso ={
  SSOUrl : "/user/oauth/verify?beforeUrl=",
  go:function () {
    var root = 'http://192.168.1.125:1512/vmdb-sso/';
    var beforeUrl = encodeURIComponent(window.location.href);
    var callbackUrl = encodeURIComponent(beforeUrl+"/sso/client/oauth/ssoCallback");
    var url = root + sso.SSOUrl + beforeUrl;
     url += "&callbackUrl="+callbackUrl;
    console.log(url);
    window.location = url;
  }
};
app.factory('HttpInterceptor',['$q',function ($q) {
  return {
    request: function (config) {
      var token = false;
      token = 'eqtFq47ald2O0UysxzdaCpYa11JW/PdQ2Wu8+uBo4nk=';
      config.headers.token = token;
      return config
    },
    response: function (res) {
      if(res.config.method == 'GET') {
        return res
      }else {
        return res.data
      }
    },
    responseError: function (result) {
      if(result.status == -1) {
        // sso.go();
        console.log('请求失败');
        return

      }
      return $q.reject(result);
    }
  }
}]);
//注入服务
app.config(['$httpProvider',function ($httpProvider) {
  $httpProvider.interceptors.push("HttpInterceptor");
}]);

export default app;
//加入路由（现在没有好的想法进行疯转）

